import React from 'react';
import { Router, Route, Switch } from 'react-router-dom';
import NotFound from './pages/NotFound';
import { useAppSelector } from './store';
import history from '@/utils/history';
import Article from './pages/Article';
import Chat from './pages/Profile/Chat';
import ProfileEdit from './pages/Profile/Edit';
import ProfileFeedback from './pages/Profile/Feedback';
import Search from './pages/Search';
import Result from './pages/Search/Result';
import Test from './pages/Test';
const Layout = React.lazy(() => import('@/pages/Layout'));
const Login = React.lazy(() => import('@/pages/Login'));

export default function App() {
  const { profile } = useAppSelector((state) => state.user);
  console.log('profile  ----->  ', profile);
  return (
    // 自行组装BrowserRouter : Router + History
    <Router history={history}>
      <React.Suspense fallback={<div>...加载中...</div>}>
        <Switch>
          <Route path="/login" component={Login} />
          <Route path="/layout" component={Layout} />
          <Route path="/search" component={Search} />
          <Route path="/article/:id" component={Article} />
          <Route path="/search/result" component={Result} />
          <Route path="/profile/edit" component={ProfileEdit} />
          <Route path="/profile/feedback" component={ProfileFeedback} />
          <Route path="/profile/chat" component={Chat} />
          <Route path="/test" component={Test} />
          <Route component={NotFound} />
        </Switch>
      </React.Suspense>
    </Router>
  );
}
